package com.ibr.ticketmanagement.app;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.ibr.ticketmanagement.app.data.ActionPlan;
import com.ibr.ticketmanagement.app.util.Utility;


public class ActionPlanActivity extends ActionBarActivity {
    public static ActionPlan actionPlan = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        actionPlan = Utility.getLatestActionPlan(ActionPlanActivity.this);
        if (actionPlan != null) {
            setContentView(R.layout.activity_action_plan);
            setActionPlanInView(actionPlan);
        } else {
            setContentView(R.layout.no_action_plan);
            // TODO: send to list.
            // TODO: check if more action plans are available.
        }
    }

    private void setActionPlanInView(ActionPlan actionPlan) {
        ((TextView) findViewById(R.id.ticketId)).setText("Ticket #" + String.valueOf(actionPlan.getTicketId()));
        ((TextView) findViewById(R.id.ticket_ww_start)).setText(Utility.getDateString(actionPlan.getwWStart()));
        ((TextView) findViewById(R.id.ticket_name)).setText(actionPlan.getName());
        ((TextView) findViewById(R.id.ticket_action_plan_desc)).setText(Html.fromHtml(actionPlan.getActionPlan()));
        ((TextView) findViewById(R.id.ticket_site_contact)).setText("Site Contact: " + actionPlan.getSiteContact());
        ((TextView) findViewById(R.id.ticket_site_access)).setText(actionPlan.getSiteAccess());
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.action_plan, menu);
        return false;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void createFEReport(View view) {
        switch (view.getId()) {
            case R.id.ticket_submit_fe_report:
                Intent feReport = new Intent(getApplicationContext(), FEReportActivity.class);
                feReport.putExtra("ac_ticket_number", actionPlan.getTicketId());
                feReport.putExtra("ac_id", actionPlan.get_id());
                startActivity(feReport);
                finish();
                break;
        }
    }
}
